package JAVA300.第十一章多线程;

import java.util.ArrayList;
import java.util.List;

/**
 * 线程不安全---操作容器--添加同步块
 */

public class thread_15_synchronized1_safe3 {
    public static void main(String[] args) {

        List<String> list = new ArrayList<>();
        for (int i=0;i<100000;i++){
            new Thread(()->{
                //同步块
                synchronized (list){
                    list.add(Thread.currentThread().getName());
                }

            }).start();
        }
        System.out.println(list.size());//100000

    }



}


